home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / frasr182.zip / HELPCOM.H < prev    next >
C/C++ Source or Header  |  1992-07-10  |  17KB  |  813 lines

  1.  
  2. /*
  3.  * helpcom.h
  4.  *
  5.  *
  6.  * Common #defines, structures and code for HC.C and HELP.C
  7.  *
  8.  */
  9.  
  10. #ifndef HELPCOM_H
  11. #define HELPCOM_H
  12.  
  13. #include "port.h"
  14.  
  15. /*
  16.  * help file signature
  17.  * If you get a syntax error, remove the LU from the end of the number.
  18.  */
  19.  
  20. #define HELP_SIG       (0xAFBC1823LU)
  21.  
  22.  
  23. /*
  24.  * commands imbedded in the help text
  25.  */
  26.  
  27. #define CMD_LITERAL      1   /* next char taken literally */
  28. #define CMD_PARA      2   /* paragraph start code */
  29. #define CMD_LINK      3   /* hot-link start/end code */
  30. #define CMD_FF          4   /* force a form-feed */
  31. #define CMD_XONLINE      5   /* exclude from online help on/off */
  32. #define CMD_XDOC      6   /* exclude from printed document on/off */
  33. #define CMD_CENTER      7   /* center this line */
  34. #define CMD_SPACE      8   /* next byte is count of spaces */
  35.  
  36. #define MAX_CMD       8
  37.  
  38.  
  39. /*
  40.  * on-line help dimensions
  41.  */
  42.  
  43. #define SCREEN_WIDTH      (78)
  44. #define SCREEN_DEPTH      (22)
  45. #define SCREEN_INDENT      (1)
  46.  
  47.  
  48. /*
  49.  * printed document dimensions
  50.  */
  51.  
  52. #define PAGE_WIDTH       (72)  /* width of printed text */
  53. #define PAGE_INDENT       (2)     /* indent all text by this much */
  54. #define TITLE_INDENT       (1)     /* indent titles by this much */
  55.  
  56. #define PAGE_RDEPTH       (59)  /* the total depth (inc. heading) */
  57. #define PAGE_HEADING_DEPTH (3)     /* depth of the heading */
  58. #define PAGE_DEPTH       (PAGE_RDEPTH-PAGE_HEADING_DEPTH) /* depth of text */
  59.  
  60.  
  61. /*
  62.  * Document page-break macros.    Goto to next page if this close (or closer)
  63.  * to end of page when starting a CONTENT, TOPIC, or at a BLANK line.
  64.  */
  65.  
  66. #define CONTENT_BREAK (7)  /* start of a "DocContent" entry */
  67. #define TOPIC_BREAK   (4)  /* start of each topic under a DocContent entry */
  68. #define BLANK_BREAK   (2)  /* a blank line */
  69.  
  70.  
  71. /*
  72.  * tokens returned by find_token_length
  73.  */
  74.  
  75. #define TOK_DONE    (0)   /* len == 0          */
  76. #define TOK_SPACE   (1)   /* a run of spaces      */
  77. #define TOK_LINK    (2)   /* an entire link      */
  78. #define TOK_PARA    (3)   /* a CMD_PARA       */
  79. #define TOK_NL        (4)   /* a new-line ('\n')    */
  80. #define TOK_FF        (5)   /* a form-feed (CMD_FF) */
  81. #define TOK_WORD    (6)   /* a word          */
  82. #define TOK_XONLINE (7)   /* a CMD_XONLINE      */
  83. #define TOK_XDOC    (8)   /* a CMD_XDOC       */
  84. #define TOK_CENTER  (9)   /* a CMD_CENTER      */
  85.  
  86.  
  87. /*
  88.  * modes for find_token_length() and find_line_width()
  89.  */
  90.  
  91. #define ONLINE 1
  92. #define DOC    2
  93.  
  94.  
  95. /*
  96.  * struct PD_INFO used by process_document()
  97.  */
  98.  
  99. typedef struct
  100.    {
  101.  
  102.    /* used by process_document -- look but don't touch! */
  103.  
  104.    int         pnum,
  105.          lnum;
  106.  
  107.    /* PD_GET_TOPIC is allowed to change these */
  108.  
  109.    char far *curr;
  110.    unsigned  len;
  111.  
  112.    /* PD_GET_CONTENT is allowed to change these */
  113.  
  114.    char far *id;
  115.    char far *title;
  116.    int         new_page;
  117.  
  118.    /* general parameters */
  119.  
  120.    char far *s;
  121.    int         i;
  122.  
  123.  
  124.    } PD_INFO;
  125.  
  126.  
  127. /*
  128.  * Commands passed to (*get_info)() and (*output)() by process_document()
  129.  */
  130.  
  131. enum  PD_COMMANDS
  132.    {
  133.  
  134. /* commands sent to pd_output */
  135.  
  136.    PD_HEADING,           /* call at the top of each page */
  137.    PD_FOOTING,        /* called at the end of each page */
  138.    PD_PRINT,        /* called to send text to the printer */
  139.    PD_PRINTN,        /* called to print a char n times */
  140.    PD_PRINT_SEC,    /* called to print the section title line */
  141.    PD_START_SECTION,    /* called at the start of each section */
  142.    PD_START_TOPIC,    /* called at the start of each topic */
  143.    PD_SET_SECTION_PAGE, /* set the current sections page number */
  144.    PD_SET_TOPIC_PAGE,    /* set the current topics page number */
  145.    PD_PERIODIC,     /* called just before curr is incremented to next token */
  146.  
  147. /* commands sent to pd_get_info */
  148.  
  149.    PD_GET_CONTENT,
  150.    PD_GET_TOPIC,
  151.    PD_RELEASE_TOPIC,
  152.    PD_GET_LINK_PAGE
  153.  
  154.    } ;
  155.  
  156.  
  157. typedef int (*PD_FUNC)(int cmd, PD_INFO *pd, VOIDPTR info);
  158.  
  159.  
  160. int _find_token_length(char far *curr, unsigned len, int *size, int *width);
  161. int find_token_length(int mode, char far *curr, unsigned len, int *size, int *width);
  162. int find_line_width(int mode, char far *curr, unsigned len);
  163. int process_document(PD_FUNC get_info, PD_FUNC output, VOIDPTR info);
  164.  
  165.  
  166. /*
  167.  * Code common to both HC.C and HELP.C (in Fractint).
  168.  * #include INCLUDE_COMMON once for each program
  169.  */
  170.  
  171.  
  172. #endif
  173. #ifdef INCLUDE_COMMON
  174.  
  175.  
  176. #ifndef XFRACT
  177. #define getint(ptr) (*(int far *)(ptr))
  178. #define setint(ptr,n) (*(int far *)(ptr)) = n
  179. #else
  180. /* Get an int from an unaligned pointer
  181.  * This routine is needed because this program uses unaligned 2 byte
  182.  * pointers all over the place.
  183.  */
  184. getint(ptr)
  185. char *ptr;
  186. {
  187.     int s;
  188.     bcopy(ptr,&s,sizeof(int));
  189.     return s;
  190. }
  191.  
  192. /* Set an int to an unaligned pointer */
  193. void setint(ptr, n)
  194. int n;
  195. char *ptr;
  196. {
  197.     bcopy(&n,ptr,sizeof(int));
  198. }
  199. #endif
  200.  
  201.  
  202. static int is_hyphen(char far *ptr)   /* true if ptr points to a real hyphen */
  203.    {                   /* checkes for "--" and " -" */
  204.    if ( *ptr != '-' )
  205.       return (0);    /* that was easy! */
  206.  
  207.    --ptr;
  208.  
  209.    return ( *ptr!=' ' && *ptr!='-' );
  210.    }
  211.  
  212.  
  213. int _find_token_length(register char far *curr, unsigned len, int *size, int *width)
  214.    {
  215.    register int _size  = 0;
  216.    register int _width = 0;
  217.    int tok;
  218.  
  219.    if (len == 0)
  220.       tok = TOK_DONE;
  221.  
  222.    else
  223.       {
  224.       switch ( *curr )
  225.      {
  226.      case ' ':    /* it's a run of spaces */
  227.         tok = TOK_SPACE;
  228.         while ( *curr == ' ' && _size < len )
  229.            {
  230.            ++curr;
  231.            ++_size;
  232.            ++_width;
  233.            }
  234.         break;
  235.  
  236.      case CMD_SPACE:
  237.         tok = TOK_SPACE;
  238.         ++curr;
  239.         ++_size;
  240.         _width = *curr;
  241.         ++curr;
  242.         ++_size;
  243.         break;
  244.  
  245.      case CMD_LINK:
  246.         tok = TOK_LINK;
  247.             _size += 1+3*sizeof(int); /* skip CMD_LINK + topic_num + topic_off + page_num */
  248.             curr += 1+3*sizeof(int);
  249.  
  250.         while ( *curr != CMD_LINK )
  251.            {
  252.            if ( *curr == CMD_LITERAL )
  253.           {
  254.           ++curr;
  255.           ++_size;
  256.           }
  257.            ++curr;
  258.            ++_size;
  259.            ++_width;
  260.            assert(_size < len);
  261.            }
  262.  
  263.         ++_size;   /* skip ending CMD_LINK */
  264.         break;
  265.  
  266.      case CMD_PARA:
  267.         tok = TOK_PARA;
  268.         _size += 3;     /* skip CMD_PARA + indent + margin */
  269.         break;
  270.  
  271.      case CMD_XONLINE:
  272.         tok = TOK_XONLINE;
  273.         ++_size;
  274.         break;
  275.  
  276.      case CMD_XDOC:
  277.         tok = TOK_XDOC;
  278.         ++_size;
  279.         break;
  280.  
  281.      case CMD_CENTER:
  282.         tok = TOK_CENTER;
  283.         ++_size;
  284.         break;
  285.  
  286.      case '\n':
  287.         tok = TOK_NL;
  288.         ++_size;
  289.         break;
  290.  
  291.      case CMD_FF:
  292.         tok = TOK_FF;
  293.         ++_size;
  294.         break;
  295.  
  296.      default:   /* it must be a word */
  297.         tok = TOK_WORD;
  298.         while (1)
  299.            {
  300.            if ( _size >= len )
  301.           break;
  302.  
  303.            else if ( *curr == CMD_LITERAL )
  304.           {
  305.           curr += 2;
  306.           _size += 2;
  307.           _width += 1;
  308.           }
  309.  
  310.            else if ( *curr == '\0' )
  311.           {
  312.           assert(0);
  313.           }
  314.  
  315.            else if ((unsigned)*curr <= MAX_CMD || *curr == ' ' ||
  316.             *curr == '\n')
  317.           break;
  318.  
  319.            else if ( *curr == '-' )
  320.           {
  321.           ++curr;
  322.           ++_size;
  323.           ++_width;
  324.           if ( is_hyphen(curr-1) )
  325.              break;
  326.           }
  327.  
  328.            else
  329.           {
  330.           ++curr;
  331.           ++_size;
  332.           ++_width;
  333.           }
  334.            }
  335.         break;
  336.      } /* switch */
  337.       }
  338.  
  339.    if (size  != NULL)    *size  = _size;
  340.    if (width != NULL)    *width = _width;
  341.  
  342.    return (tok);
  343.    }
  344.  
  345.  
  346. int find_token_length(int mode, char far *curr, unsigned len, int *size, int *width)
  347.    {
  348.    int tok;
  349.    int t;
  350.    int _size;
  351.  
  352.    tok = _find_token_length(curr, len, &t, width);
  353.  
  354.    if ( (tok == TOK_XONLINE && mode == ONLINE) ||
  355.     (tok == TOK_XDOC    && mode == DOC)     )
  356.       {
  357.       _size = 0;
  358.  
  359.       while (1)
  360.      {
  361.      curr  += t;
  362.      len   -= t;
  363.      _size += t;
  364.  
  365.      tok = _find_token_length(curr, len, &t, NULL);
  366.  
  367.      if ( (tok == TOK_XONLINE && mode == ONLINE) ||
  368.           (tok == TOK_XDOC      && mode == DOC)    ||
  369.           (tok == TOK_DONE)                )
  370.         break;
  371.      }
  372.  
  373.       _size += t;
  374.       }
  375.    else
  376.       _size = t;
  377.  
  378.    if (size != NULL )
  379.       *size = _size;
  380.  
  381.    return (tok);
  382.    }
  383.  
  384.  
  385. int find_line_width(int mode, char far *curr, unsigned len)
  386.    {
  387.    int size   = 0,
  388.        width  = 0,
  389.        lwidth = 0,
  390.        done   = 0,
  391.